<%@ page import="com.xiaoyi.pojo.RoomTypeStatus" %><%--
  Created by IntelliJ IDEA.
  User: 世界上最帅的詹姆斯
  Date: 2021-01-15
  Time: 11:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/";
    //获取session中的值
    RoomTypeStatus room = (RoomTypeStatus) session.getAttribute("room");
    String rimg = room.getRimg();
    String[] split = rimg.split("\\\\");

%>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link href="../../layui/css/layui.css" media="all" rel="stylesheet">
<body>

    <center>
        <form class=" layui-form layui-form-pane" method="post">
            <div class="layui-form-item">
                <div class="layui-inline" style="top: 90px;width: 250px">
                    <label class="layui-form-label">ID</label>
                    <div class="layui-input-inline">
                        <input type="text" name="id" disabled value=${room.id} autocomplete="off" class="layui-input"
                               placeholder="ID为整型">
                    </div>
                </div>
            </div>
            <dic class="layui-form-item">
                <div class="layui-inline" style="top: 120px;width: 250px">
                    <label class="layui-form-label">房间类型</label>
                    <div class="layui-input-inline">
                        <input type="text" name="rtname" value="${room.rtname}" autocomplete="off" class="layui-input"
                               placeholder="请输入房间类型">
                    </div>
                </div>
            </dic>
            <dic class="layui-form-item">
                <div class="layui-inline" style="top: 150px;width: 250px">
                    <label class="layui-form-label">房间价格</label>
                    <div class="layui-input-inline">
                        <input type="text" name="rtprice" value=${room.rtprice} autocomplete="off" class="layui-input"
                               placeholder="请输入房间价格">
                    </div>
                </div>
            </dic>
            <dic class="layui-form-item">
                <div class="layui-inline" style="top: 180px;width: 250px">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test1">上传图片</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo1" src="<%=basePath+split[2]%>" style="width: 80px;height: 80px">
                            <p id="demoText"></p>
                        </div>
                    </div>
                </div>
            </dic>
            <div class="layui-form-item">
                <div class="layui-input-block" style="top: 180px;left: -50px">
                    <button type="submit" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit=""
                            lay-filter="demo1">立即提交
                    </button>
                    <button type="reset" class="layui-btn layui-btn-primary layui-btn-radius">重置</button>
                </div>
            </div>
        </form>
    </center>
    <script src="../../layui/layui.js"></script>
    <script type="text/javascript">
        layui.use(['form', 'jquery','upload'], function () {
            var form = layui.form;
            var $ = layui.jquery;
            var upload=layui.upload;
            //监听提交
            form.on('submit(demo1)', function (data) {
                var index = layer.msg('提交中，请稍候', {icon: 16, time: false, shade: 0.8});
                $.ajax({
                    url: '<%=basePath%>basic/updateRoomTypeStatus',
                    dataType: 'json',
                    type: 'post',
                    data: data.field,
                    async: false,
                    success: function (data) {
                        if (data === false) {
                            layer.msg('修改失败！', {
                                icon: 5,
                                offset: "auto",
                                time: 2000
                            });//提示框
                        } else if (data === true) {
                            layer.alert('修改成功', {incon: 6}, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                                //修改成功后刷新父界面
                                window.parent.location.reload();
                            })
                        }
                    }
                })
                return false;
            })
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                ,url: '<%=basePath%>user/uploadImg' //改成您自己的上传接口
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    //上传成功

                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        })


    </script>
</body>
</html>
